package com.gwnet.cabinet.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gwnet.cabinet.domian.Cabinet;
import com.gwnet.cabinet.domian.bo.CabinetAddBO;
import com.gwnet.cabinet.domian.bo.CabinetDevSnBO;
import com.gwnet.cabinet.domian.bo.CabinetPageBO;
import com.gwnet.cabinet.service.CabinetService;
import com.gwnet.common.core.domain.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 外卖柜表 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-07-23
 */
@RestController
@RequestMapping("/cabinet")
public class CabinetController {


    private final CabinetService cabinetService;

    @Autowired
    public CabinetController(CabinetService cabinetService) {
        this.cabinetService = cabinetService;
    }

    /**
     * 分页查询列表
     * @param pageBO
     * @return
     */
    @PostMapping("/page")
    public ResponseResult<IPage<Cabinet>> page(@RequestBody CabinetPageBO pageBO){
        IPage<Cabinet> page = cabinetService.page(pageBO);
        return ResponseResult.success(page);
    }


    /**
     * 根据设备ID查询设备
     * @param devSnBO 设备ID
     * @return
     */
    @PostMapping("/view")
    public ResponseResult<Cabinet> view(@RequestBody CabinetDevSnBO devSnBO){
        Cabinet view = cabinetService.view(devSnBO.getDevSn());
        return ResponseResult.success(view);
    }

    /**
     * 新增
     * @param addBO
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody CabinetAddBO addBO){
        Boolean add = cabinetService.add(addBO);
        return ResponseResult.success(add);
    }

    /**
     * 根据Id删除
     * @param devSnBO
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult<Boolean> delete(@RequestBody CabinetDevSnBO devSnBO){
        Boolean flag = cabinetService.delete(devSnBO.getDevSn());
        return ResponseResult.success(flag);
    }

    /**
     * 根据Id删除，多个id用”,“隔开
     * @param devSnBO
     * @return
     */
    @PostMapping("/deleteBatch")
    public ResponseResult<Boolean> deleteBatch(@RequestBody CabinetDevSnBO devSnBO){
        Boolean flag = cabinetService.deleteBatch(devSnBO.getDevSn());
        return ResponseResult.success(flag);
    }













}

